# I             1
# V             5
# X             10
# L             50
# C             100
# D             500
# M             1000

class Solution:
    def romanToInt(self, s: str) -> int:
        result = 0
        table1 = dict(zip('IVXLCDM', [1, 5, 10, 50, 100, 500, 1000]))
        table2 = {
            'IV': 4,
            'IX': 9,
            'XL': 40,
            'XC': 90,
            'CD': 400,
            'CM': 900
        }
        i = 0
        while i < len(s):
            if i < len(s) -1 and s[i: i+2] in table2:
                result += table2[s[i: i+2]]
                i += 2
            else:
                result += table1[s[i]]
                i += 1
        return result


print(Solution().romanToInt('I'))
print(Solution().romanToInt('II'))
print(Solution().romanToInt('III'))
print(Solution().romanToInt('IV'))
print(Solution().romanToInt('XIV'))
print(Solution().romanToInt('XIX'))
print(Solution().romanToInt('XX'))
print(Solution().romanToInt('MMMCMXCIX'))
